import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
			path: '/',
			name: 'login',
			component: () => import('../views/Login.vue')
		},
		{
			path: '/login',
			name: 'login',
			component: () => import('../views/Login.vue')
		},
		
		
			{
			path: '/main',
			name: 'main',
			component: () => import('../views/Main.vue'),
			redirect: '/home',
			children: [{
					path: '/home',
					name: 'home',
					component: () => import('@/views/Home.vue')
				},
				{
					path: '/article',
					name: 'article',
					component: () => import('@/views/content/Article.vue')
				},
				{
					path: '/articletype',
					name: 'articletype',
					component: () => import('@/views/content/ArticleType.vue')
				},
				{
					path: '/course',
					name: 'course',
					component: () => import('@/views/course/Course.vue')
				},
				{
					path: '/fm',
					name: 'fm',
					component: () => import('@/views/content/Fm.vue')
				},
				{

					path: '/consult',
					name: 'consult',
					component: () => import('@/views/consult/Consult.vue')
				},
				{
					path: '/consultLv',
					name: 'consultLv',
					component: () => import('@/views/consult/ConsultLv.vue')
				},
				{
					path: '/field',
					name: 'field',
					component: () => import('@/views/consult/Field.vue')
				},
				{
					path: '/chargeType',
					name: 'chargeType',
					component: () => import('@/views/consult/ChargeType.vue')
				},
				{
					path: '/charge',
					name: 'charge',
					component: () => import('@/views/consult/Charge.vue')
				},
				{
					path: '/psychology',
					name: 'psychology',
					component: () => import('@/views/content/Psychology.vue')
				},
				{
					path: '/mentaltest',
					name: 'mentaltest',
					component: () => import('@/views/content/MentalTest.vue')
				},
				{
					path: '/commonweal',
					name: 'commonweal',
					component: () => import('@/views/content/Commonweal.vue')
				},
				{
					path: '/courseType',
					name: 'courseType',
					component: () => import('@/views/course/CourseType.vue')
				},
				{
					path: '/courseEvaluation',
					name: 'courseEvaluation',
					component: () => import('@/views/course/CourseEvaluation.vue')
				},
				{
					path: '/question',
					name: 'question',
					component: () => import('@/views/mentalAnswer/Question.vue')
				},
				{
					path: '/reply',
					name: 'reply',
					component: () => import('@/views/mentalAnswer/Reply.vue')
				},
				{
					path: '/appointment',
					name: 'appointment',
					component: () => import('@/views/reservation/Appointment.vue')
				},
				{
					path: '/assessment',
					name: 'assessment',
					component: () => import('@/views/reservation/Assessment.vue')
				},
				{
					path: '/consultreply',
					name: 'consultreply',
					component: () => import('@/views/reservation/Reply.vue')
				},
				{
					path: '/rootUser',
					name: 'rootUser',
					component: () => import('@/views/system/RootUser.vue')
				},
				{
					path: '/user',
					name: 'user',
					component: () => import('@/views/system/User.vue')
				},
				{
					path: '/consultNotice',
					name: 'consultNotice',
					component: () => import('@/views/system/ConsultNotice.vue')
				},
				{
					path: '/company',
					name: 'company',
					component: () => import('@/views/system/Company.vue')
				},
				{
					path: '/centre',
					name: 'centre',
					component: () => import('@/views/system/Centre.vue')
				},
				{
					path: '/editPassword',
					name: 'editPassword',
					component: () => import('@/views/system/EditPassword.vue')
				}
				]
			},

			// {
			//   path: '/about',
			//   name: 'about',
			//   // route level code-splitting
			//   // this generates a separate chunk (about.[hash].js) for this route
			//   // which is lazy-loaded when the route is visited.
			//   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
			// }
		]

		const router = new VueRouter({
			routes
		})


// 挂载路由导航守卫,to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作
// 添加路由守卫
// to:要去访问的请求名   from：从哪里出发    next:下一个请求，进行跳转
router.beforeEach((to,from,next)=>{
	if(to.path === '/login'){
		return next();  // 放行
	}
	// 动态的获取sessionStorage中的数据
	let username = sessionStorage.getItem('username');
	if(!username){   // 没有登录，则跳转到登录页面
		
		return next('/login');   
	}
	// 如果登录则放行
	next();
})
		export default router